<template>
  <el-cascader
    :value="value"
    size="mini"
    :options="depts"
    :props="{label:'name',value:'id'}"
    separator="/"
    @change="changeValue"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  // v-model=  input +value
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      depts: []
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.depts = transListToTreeData(await getDepartment(), 0)
    },
    changeValue(list) {
    //   console.log(list)
      if (list.length) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
